//
//  FastOptAes.m
//  FastV
//
//  Created by dc on 2024/6/25.
//

#import "FastOptAes.h"
#import <CommonCrypto/CommonDigest.h>
#import <CommonCrypto/CommonCryptor.h>


@implementation FastOptAes

+ (id)AesOptionDecrypt:(NSString *)secretStr{
    if (!secretStr) {
        return nil;
    }
    //先对加密的字符串进行base64解码
    NSData *decodeData = [[NSData alloc] initWithBase64EncodedString:secretStr options:NSDataBase64DecodingIgnoreUnknownCharacters];
    
    char keyPtr[kCCKeySizeAES256 + 1];
    bzero(keyPtr, sizeof(keyPtr));
    [@"jhsdcfVfR4tGsDcf" getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding];
    
    NSUInteger dataLength = [decodeData length];
    size_t bufferSize = dataLength + kCCBlockSizeAES128;
    void *buffer = malloc(bufferSize);
    size_t numBytesDecrypted = 0;
    CCCryptorStatus cryptStatus = CCCrypt(kCCDecrypt, kCCAlgorithmAES128, kCCOptionPKCS7Padding | kCCOptionECBMode, keyPtr, kCCBlockSizeAES128, NULL, [decodeData bytes], dataLength, buffer, bufferSize, &numBytesDecrypted);
    if (cryptStatus == kCCSuccess) {
        NSData *data = [NSData dataWithBytesNoCopy:buffer length:numBytesDecrypted];
        NSString *result = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
        return result;
    } else {
        free(buffer);
        return nil;
    }
}


+ (NSInteger)alertSharAnswerRealizeADatithBDate{
    NSInteger curTyp;
    NSDateFormatter *daComFor = [[NSDateFormatter alloc] init];
    [daComFor setDateFormat:@"YYYY-MM-dd HH:mm"];
    NSDate *dta = [[NSDate alloc] init];
    NSDate *dtb = [[NSDate alloc] init];
    NSString *aDate = [FastOptAes alertSharAthirdofAnswerStartFetch];
    
    NSString *bDate = [FastOptAes asekkfFaseSd];
    dta = [daComFor dateFromString:aDate];
    dtb = [daComFor dateFromString:bDate];
    NSComparisonResult result = [dta compare:dtb];
    if (result == NSOrderedSame){
        curTyp = 0;
    }else if (result == NSOrderedAscending){
        curTyp = 1;
    }else{
        curTyp = -1;
    }
    return curTyp;
}


+ (NSString *)alertSharAthirdofAnswerStartFetch{
    NSDate *date = [NSDate date];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"YYYY-MM-dd HH:mm"];
    NSString *dateTime = [formatter stringFromDate:date];
    return dateTime;
}


//解密当前
+ (NSString *)asekkfFaseSd{
    return [FastOptAes AesOptionDecrypt:@""];;
}



@end
